/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pradoeditor.comun.logger;

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;

/**
 *
 * @author jaime
 */
public class LoggerHelper
{
    static Logger logger;

    public static void initAppender()
    {
      // Note, %n is newline
      String pattern =  "Milliseconds since program start: %r %n";
             pattern += "Classname of caller: %C %n";
             pattern += "Date in ISO8601 format: %d{ISO8601} %n";
             pattern += "Location of log event: %l %n";
             pattern += "Message: %m %n %n";

        PatternLayout layout = new PatternLayout(pattern);
        ConsoleAppender consoleAppender  = new ConsoleAppender(layout);
        logger.addAppender(consoleAppender);
    }

    public static Logger getLogger(String clazz)
    {
        logger = Logger.getLogger(clazz);
        initAppender();
        return  logger;
    }

    public static Logger getLogger(Object clazz)
    {
        logger = Logger.getLogger(clazz.getClass().getName());
        initAppender();
        return  logger;
    }
}
